<template>
  <van-popup
    :value="value"
    @input="$emit('input',$event)"
    :close-on-click-overlay='!isReport'
    @click="!isReport"
  >
    <van-cell-group v-if="!isReport">
      <van-cell
        @click="dislikeFn"
        icon="closed-eye"
      >不感兴趣</van-cell>
      <van-cell
        is-link
        @click="isReport=true"
      >反馈垃圾内容</van-cell>
      <van-cell icon="info-o">拉黑作者</van-cell>
    </van-cell-group>

    <van-cell-group v-else>
      <van-cell
        icon="arrow-left"
        @click="isReport=false"
      >返回</van-cell>
      <van-cell
        v-for="item in reports"
        :key="item.value"
        @click="reportArticleFn(item.value)"
      >{{item.label}}</van-cell>
    </van-cell-group>
  </van-popup>
</template>

<script>
import { disLikeById, reportById } from '@/api/news'
import { reports } from '@/utils/const'
export default {
  props: {
    value: {
      type: Boolean,
      default: false
    },
    articleId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      // 是否显示上报垃圾内容
      isReport: false,
      // 举报类型
      reports
    }
  },
  methods: {
    async dislikeFn () { // 更多-不喜欢
      try {
        await disLikeById(this.articleId)
        this.$toast.success('将减少此类文章')
        this.$emit('on-dislike')
        this.$emit('input', false)
      } catch (error) {
        console.log(error)
      }
    },
    async reportArticleFn (type) { // 举报
      try {
        await reportById(this.articleId, type)
        this.$toast.success('举报成功')
        this.$emit('on-report')
        this.$emit('input', false)
      } catch (error) {

      }
    }
  }
}
</script>

<style scoped lang='less'>
.van-popup {
  width: 80%;
  border-radius: 4px;
}
</style>
